package com.zhouhuo.serviceedu.controller;


import com.zhouhuo.commonutils.R;
import com.zhouhuo.serviceedu.entity.EduTeacher;
import com.zhouhuo.serviceedu.service.IEduTeacherService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 讲师 前端控制器
 * </p>
 *
 * @author zhouhuo
 * @since 2020-06-07
 */
@Api(value = "讲师管理")
@RestController
@RequestMapping("/edu/teacher")
@CrossOrigin
public class EduTeacherController {

  @Autowired
  private IEduTeacherService eduTeacherService ;

  /**
   * 获取所有的讲师列表
   * @return
   */
  @ApiOperation(value = "所有讲师列表")
  @GetMapping("list")
  public R list() {
    List<EduTeacher> teacherList = eduTeacherService.list(null) ;
    return  R.ok().data("items", teacherList);
  }

  /**
   * 删除讲师
   * @param id
   * @return
   */
  @ApiOperation(value = "根据 ID 删除讲师")
  @DeleteMapping("{id}")
  public R removeById(@ApiParam(name = "id", value = "讲师ID", required = true)
      @PathVariable String id) {
    boolean isOk = eduTeacherService.removeById(id) ;
    if(isOk) {
      return R.ok() ;
    } else {
      return R.error().message("讲师删除失败") ;
    }
  }

}

